package com.gitee.qdbp.base.orm.mybatis.dialect.impl;

import java.util.HashMap;
import java.util.Map;
import com.gitee.qdbp.able.jdbc.paging.Paging;
import com.gitee.qdbp.base.orm.mybatis.constant.Const;
import com.gitee.qdbp.base.orm.mybatis.dialect.Dialect;

/**
 * mysql方言
 *
 * @author gj
 * @version 150211
 */
public class MySqlDialect extends Dialect {

    /**
     * {@inheritDoc}
     */
    @Override
    public String generatePageSQL(String sql) {
        StringBuilder sqlBuilder = new StringBuilder(sql.length() + 14);
        sqlBuilder.append(sql);
        sqlBuilder.append(" limit ?,?");
        return sqlBuilder.toString();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String generateCountSQL(String sql) {
        return parser.getSmartCountSql(sql);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Map<String, Object> getPageParameter(Paging paging) {
        Map<String, Object> param = new HashMap<String, Object>();
        param.put(Const.PARAMETER_FIRST, paging.getStart());
        param.put(Const.PARAMETER_SECOND, paging.getRows());
        return param;
    }

}
